/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.dispositivos;

import com.mapping.Dispositivo;
import com.mapping.Software;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="verSoftware", results={@Result(name="success",location="/GestionDispositivos/rVerSoftware.jsp")})
public class VerSoftwareAction extends ActionSupport{
    private String id;
    private List<Software> listaSoft;
    private List<Software> listaSoftAdded;
    private DispositivoDetalle dd;
    
    @Override
    public String execute(){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        listaSoft = (List<Software>) em.createNamedQuery("Software.findAll").getResultList();
        Dispositivo disp = (Dispositivo)em.getReference(Dispositivo.class, id);
        dd = ListaDispositivos.getDispositivoDetalle(disp);
        listaSoftAdded = (List<Software>) disp.getSoftwareCollection();
        tx.commit();
        em.close();
        return SUCCESS;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<Software> getListaSoft() {
        return listaSoft;
    }

    public List<Software> getListaSoftAdded() {
        return listaSoftAdded;
    }

    public DispositivoDetalle getDd() {
        return dd;
    }
    
}
